package com.mayflygeek.mayflyask.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;

import org.hibernate.validator.constraints.NotBlank;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mayflygeek.mayflyask.util.UserUtils;

/**
 * @author 蝈蝈 
 * @email guodefu909@126.com
 * @team 蜉蝣极客
 * @link www.mayflygeek.com 
 * 实体类
 */
@Entity
@Table(name = "mayflyask_role")
public class Role implements Serializable {

	private static final long serialVersionUID = 1L;
	private Long id;
	private String roleName;

	private Integer status;
	private Date updatedTime;
	private Long updater;
	private Date createdTime;
	private Long creater;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@NotBlank(message = "{Role.roleName.NotBlank}")
	@Column(name = "role_name", unique = true, length = 20, nullable = false)
	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	@Column(nullable = false)
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@Column(name = "updated_time", nullable = false)
	public Date getUpdatedTime() {
		return updatedTime;
	}

	public void setUpdatedTime(Date updatedTime) {
		this.updatedTime = updatedTime;
	}

	@Column(nullable = false)
	public Long getUpdater() {
		return updater;
	}

	public void setUpdater(Long updater) {
		this.updater = updater;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@Column(name = "created_time", nullable = false, updatable = false)
	public Date getCreatedTime() {
		return createdTime;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}

	@Column(nullable = false, updatable = false)
	public Long getCreater() {
		return creater;
	}

	public void setCreater(Long creater) {
		this.creater = creater;
	}

	@PrePersist
	public void prePersist() {
		this.updater = UserUtils.getSessionUser().getId();
		this.updatedTime = new Date();
		this.creater = this.updater;
		this.createdTime = this.updatedTime;
		status = status == null ? 1 : status;
	}

	@PreUpdate
	public void preUpdate() {
		this.updater = UserUtils.getSessionUser().getId();
		this.updatedTime = new Date();
		status = status == null ? 1 : status;
	}

}
